package com.uml.umlwork.controller;

import com.uml.umlwork.config.annotation.UserLoginToken;
import com.uml.umlwork.dto.course.select.InputScoreDTO;
import com.uml.umlwork.service.CourseSelectService;
import com.uml.umlwork.utils.PageResult;
import com.uml.umlwork.utils.SystemMsgJsonResponse;
import com.uml.umlwork.vo.course.select.CourseSelectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "选课信息相关模块 - api")
@RequestMapping("/api/v1/umlwork/courseSelect")
@RestController
@UserLoginToken
public class CourseSelectController {

    private final CourseSelectService courseSelectService;

    public CourseSelectController(CourseSelectService courseSelectService) {
        this.courseSelectService = courseSelectService;
    }

    @GetMapping("/getAllByClassId")
    @ApiOperation(value = "[培训师] - 查询班级学生的选课信息", httpMethod = "GET")
    public SystemMsgJsonResponse getAllByClassId(
            @RequestParam(value = "page", defaultValue = "1") Long current,
            @RequestParam(value = "size", defaultValue = "10") Long size,
            @RequestParam(value = "classId") Integer classId) {
        PageResult<CourseSelectVO> result = courseSelectService.getAllByClassId(current, size, classId);
        return SystemMsgJsonResponse.success(result);
    }

    @PostMapping("/inputScore")
    @ApiOperation(value = "[培训师] - 录入班级学生成绩接口", httpMethod = "POST")
    public SystemMsgJsonResponse inputScore(@RequestBody @Validated InputScoreDTO dto) {
        courseSelectService.inputScore(dto);
        return SystemMsgJsonResponse.success();
    }

    @GetMapping("/saveStatus")
    @ApiOperation(value = "[管理员] - 确定学生选课信息", httpMethod = "GET")
    public SystemMsgJsonResponse saveStatus(@RequestParam("id") Integer id,
                                            @RequestParam("confirm") Integer confirm,
                                            @RequestParam("open") Integer open) {
        courseSelectService.saveStatus(id, confirm, open);
        return SystemMsgJsonResponse.success();
    }
}
